package com.weiaibenpao.demo.chislim.ui.activity.me;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.weiaibenpao.demo.chislim.R;
import com.weiaibenpao.demo.chislim.base.BaseActivity;
import com.weiaibenpao.demo.chislim.db.preferences.UserPreferences;
import com.weiaibenpao.demo.chislim.ui.activity.MainActivity;
import com.weiaibenpao.demo.chislim.utils.Constant;
import com.weiaibenpao.demo.chislim.utils.DataCleanManagerUtils;

import butterknife.BindView;
import butterknife.OnClick;

public class SetActivity extends BaseActivity {

    @BindView(R.id.cacheNum)
    TextView cacheNum;    //用户手机缓存数据
    @BindView(R.id.catchLayout)
    RelativeLayout catchLayout;
    @BindView(R.id.opinionLayout)
    RelativeLayout opinionLayout;
    @BindView(R.id.aboutLayout)
    RelativeLayout aboutLayout;
    @BindView(R.id.basicSetLayout)
    RelativeLayout basicSetLayout;
    @BindView(R.id.userPhone)
    TextView userPhone;          //用户手机号码
    @BindView(R.id.changePhoneLayout)
    RelativeLayout changePhoneLayout;
    @BindView(R.id.closeInput)
    RelativeLayout closeInput;
    private final int CHANGE_SUCCESS=1110;

    @Override
    public int setLayoutResourceID() {
        return R.layout.activity_set;
    }

    @Override
    public void init(Bundle savedInstanceState) {
        userPhone.setText(UserPreferences.getInstance().getString(UserPreferences.USER_PHONE)+"");
         cacheNum.setText(DataCleanManagerUtils.getTotalCacheSize(getApplicationContext()));
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode==RESULT_OK){

            if (requestCode==CHANGE_SUCCESS){
//                String newPhone = data.getStringExtra(Constant.CLASS_BEAN);
                userPhone.setText(data.getStringExtra(Constant.CLASS_BEAN));
            }
        }
    }


    @OnClick({R.id.catchLayout, R.id.opinionLayout, R.id.aboutLayout, R.id.changePhoneLayout, R.id.closeInput,R.id.left_image})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.catchLayout:
                //清理缓存
                DataCleanManagerUtils.clearAllCache(getApplicationContext());
                try {
                    cacheNum.setText(0+"");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case R.id.opinionLayout:
                //意见反馈
                startActivity(new Intent(this,OpinionActivity.class));
                break;
            case R.id.aboutLayout:
                //关于东极圈
                AboutActivity.startSelf(this);
                break;
            case R.id.changePhoneLayout:
                //跟换电话号码
                startActivityForResult(new Intent(this,ChangePhoneActivity.class),CHANGE_SUCCESS);
                break;
            case R.id.closeInput:
                //退出登录
                UserPreferences.getInstance().clear();
                MainActivity.startSelfToExit(this);
                break;
            case R.id.left_image:
                finish();
                break;
        }
    }

}
